package com.ztsoft.user.controller.project;

import com.ztsoft.user.pojo.entity.project.Construction;
import com.ztsoft.user.pojo.vo.project.UnifiedForms;
import com.ztsoft.user.service.project.ConstructionService;
import com.ztsoft.user.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

@Slf4j
@CrossOrigin("*")
@RestController
@RequestMapping("/construction")
@Api(tags = "班组人员控制层")
public class ConstructionController {
    @Autowired
    private ConstructionService constructionService;

    @ApiOperation(value = "下载班组人员填写模板", notes = "下载模板并将其保存在本地文件夹中")
    @PostMapping("/exportTemplate")
    public void exportTemplate(HttpServletResponse response) {
        constructionService.exportTemplate(response);
    }

    /**
     * 上传班组人员表
     *
     * @param chooseId  物资id
     * @param file 文件列表
     * @return 响应结果
     */
    @PostMapping("/constructionAnalysis/{chooseId}")
    public Result<Object> constructionAnalysis(@PathVariable("chooseId") String chooseId, @RequestBody MultipartFile file) {
        return constructionService.parseUpLoadFile(chooseId, file);
    }

    @GetMapping("/getConstruction/{id}/{pageSize}/{currentPage}")
    public Result<Object> getConstruction(@PathVariable("id") String id,
                                          @PathVariable("pageSize") Integer pageSize,
                                          @PathVariable("currentPage") Integer currentPage) {
        return constructionService.getConstruction(id, pageSize, currentPage);
    }

    @PostMapping("/unified/{chooseId}")
    @ApiOperation(value = "班组人员统一控制接口", notes = "班组人员统一控制接口")
    public Result<Object> unified(@RequestBody UnifiedForms<Construction> unifiedForms, @PathVariable("chooseId") String chooseId) {
        return constructionService.unified(unifiedForms,chooseId);
    }

}